package com.example.wrapspringbootstarter.config;

import com.example.wrapspringbootstarter.service.SomeService;
import com.example.wrapspringbootstarter.service.SomeServiceProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(SomeService.class)
@EnableConfigurationProperties(SomeServiceProperties.class)
public class SomeServiceAutoConfigration {

//    @Autowired
//    private SomeServiceProperties someServiceProperties;

    @Bean
    @ConditionalOnProperty(name="some.service.enable",havingValue = "true",matchIfMissing = true)
    public SomeService someService(SomeServiceProperties someServiceProperties){
        return  new SomeService(someServiceProperties.getBefore(),someServiceProperties.getAfter());
    }

    @Bean
    @ConditionalOnMissingBean
    public SomeService someService2(){
        return  new SomeService("","");
    }
}
